package com.nengchuan.eic.nceconomy.config;

import com.fasterxml.jackson.databind.JsonSerializer;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Locale;

/**
 * @description: 时间格式化处理类
 * @author: panwen
 * @create: 2020/05/25 16:58
 * @version：1.0.0
 */
public class Long2DateFormatSerializer extends JsonSerializer<Long> {
    private final static DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss", Locale.CHINA);

    @Override
    public void serialize(Long l, com.fasterxml.jackson.core.JsonGenerator jsonGenerator, com.fasterxml.jackson.databind.SerializerProvider serializerProvider) throws IOException {
        String format = pattern.format(LocalDateTime.ofEpochSecond(l/1000,0, ZoneOffset.ofHours(8)));
        jsonGenerator.writeString(format);
    }
}
